*****************************************************************
* Replication directory for                                   ***
* Prime locations                                             ***
* by Gabriel M. Ahlfeldt, Thilo N.H. Albers, Kristian Behrens ***
* Published in American Economic Review: Insights             ***
*****************************************************************
* 01/2025
* Stata
version 17.0

* This do file correlates prime locations generated generated based on different employment measures 
* It validates the big data procedure against prime locations generated using the best employment data

* Load baseline employment PLs
	u "$temp/grid_PL_output_ET99/grid_PL_output_ET99__all.dta", clear
	ren PL PL_99
	label var PL_99 "PL, all employment"
	
* Merge TS employment PLs
	merge 1:1 square_id using "$temp/grid_PL_output_ET5/grid_PL_output_ET5__all.dta", keepusing(PL)
	drop _m
	ren PL PL_5
	label var PL_5 "Tradable services"
	
* Merge search-term employment PLs
	merge 1:1 square_id using "$temp/grid_PL_output_ET3/grid_PL_output_ET3__all.dta", keepusing(PL)
	drop _m
	ren PL PL_3
	label var PL_3 "Search term employment"

* Merge employment weights from first half of cities by alphabet
	merge 1:1 square_id using "$temp/grid_PL_output_ET0/grid_PL_output_ET0__all.dta", keepusing(PL)
	drop _m
	ren PL PL_0
	label var PL_0 "EWPPs, first batch"
	
* Merge employment weights from second half of cities by alphabet
	merge 1:1 square_id using "$temp/grid_PL_output_ET1/grid_PL_output_ET1__all.dta", keepusing(PL)
	drop _m
	ren PL PL_1
	label var PL_1 "EWPPs, second batch"
	
* Correlate
	foreach var of varlist PL_5 PL_3 PL_0 PL_1 {
		display ("...working on variable `var'...")
		local lab : variable label `var'
		qui gen PL_alt = `var' 
		label var PL_alt "PL, alternative employment measure"
		eststo: reg PL_99 PL_alt if developable== 1, robust
		qui estadd local AltMeasure "`lab'"	
		qui drop  PL_alt 
	}
* Write Appendix Table B.3.2
	capture mkdir "$tables_App/validation"
	esttab  using "$tables_App/validation/TAB_B3_2_Validation.tex", replace b(3) se(4) label compress   r2(3) ///
			stats(AltMeasure N r2 , fmt(%18.3g )   labels("`Alternative measure'"  `"Observations"' `"\(R^{2}\)"' ))  /// stats(Country_effects IV N r2) 0.* "`City'"
			title("Validation of delination") modelwidth(6) nogap  ///
			addnote( "Unit of observation grid cell. Undevelopable grid cells excluded. PL is a dummy taking the value of one if a grid cell belongs to at prime location, and zero otherwise." )	nostar  //  star(+ 0.15 * 0.1 ** 0.05 *** 0.01)
			eststo clear
			
* Script ends